package com.party.mobile.web.controller.cosapi;

import com.party.core.service.cos.CosBizService;
import com.party.mobile.web.dto.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 腾讯云对象存储控制器
 * Created by Juliana
 *
 * @date 2017/12/08 0016
 * @time 9:43
 */

@Controller
@RequestMapping(value = "/cos/v4/api")
public class CosV4Controller {

    @Autowired
    private CosBizService cosBizService;

    Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 获取多次有效签名
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getAppSign")
    public AjaxResult getAppSign(Integer type){
        Map<String, Object> more = cosBizService.getCosSign("more", type);
        return AjaxResult.success(more);
    }


    /**
     * 获取单次有效签名
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getAppSignOnce")
    public AjaxResult getAppSignOnce(Integer type){
        Map<String, Object> more = cosBizService.getCosSign("once", type);
        return AjaxResult.success(more);
    }

    /**
     * 获取Cos对象存储配置
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getConfig")
    public AjaxResult getConfig(Integer type){
        Map<String, Object> config = cosBizService.getConfig(type);
        return AjaxResult.success(config);
    }

    /**
     * @return
     * @Author yifeng
     * @Description 获取cos-sts的临时秘钥信息
     * @Date 17:43 2019/5/13
     **/
    @ResponseBody
    @RequestMapping(value = "/getCosStsCredentials")
    public AjaxResult getCosStsCredentials() {
        try {
            Map<String,Object> credentials = cosBizService.getCosStsCredentials();
            return AjaxResult.success(credentials);
        } catch (Exception e) {
            logger.error("获取秘钥异常", e);
            return AjaxResult.error(100, "获取秘钥异常");
        }
    }
}
